package Controller;

import entity.Emp;
import service.EmpService;
import service.impl.EmpServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 *徐韬
 *2021/9/23
 *22:21
 */
@WebServlet("/update")
public class upDateEmpController extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String salay = request.getParameter("salay");
        String age = request.getParameter("age");
        Integer id1 = Integer.valueOf(id);
        Double aDouble = Double.valueOf(salay);
        Integer age1 = Integer.valueOf(age);
        Emp emp = new Emp(id1,name,aDouble,age1);
        EmpService empService = new EmpServiceimpl();
        int i = empService.updateEmp(emp);
        if(i>0){
            response.sendRedirect("/ems/ShowAllController");
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
